#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>
#include "static.h"


typedef struct _thread_args
{
	char name[64];
	unsigned index;
	int num;
}thread_args;



#define PRINT_INFO(str) printf("[%s:%s:%d] %s\n", __FILE__, __FUNCTION__, __LINE__, str)

void print_ids(const char* pThreadName)
{
    pid_t pid = getpid();
    pthread_t tid = pthread_self();
    printf("[%s:%s:%d] %s, pid: %u, thread_id: %u(0x%x)\n",  
           __FILE__, __FUNCTION__, __LINE__, 
           pThreadName, (unsigned int)pid,  
           (unsigned int)tid, (unsigned int)tid);  	
}


void* ThreadFunc(void *args)
{
    print_ids("new thread");
	{
    	print_ids("new thread external");
	}

	thread_args *arg = (thread_args *)args;
	printf("name:%s, index:%d, num:%d\n", arg->name, arg->index, arg->num);

    return NULL;
}


int main(int argc, char* argv[])
{
    PRINT_INFO("start");

	thread_args arg = {"Bob", 1, 0 };
	
    pthread_t tid;
    int ret = pthread_create(&tid, NULL, ThreadFunc, (void *)&arg);
    if (ret != 0)
    {
          printf("[%s:%s:%d] create thread error: %s\n", __FILE__, __FUNCTION__, __LINE__, strerror(ret));
          return -1;
    }

    printf("[%s:%s:%d] main thread, pid: %u, thread_id: %u(0x%x)\n",  
    __FILE__, __FUNCTION__, __LINE__, 
    (unsigned int)getpid(), (unsigned int)pthread_self(), 
    (unsigned int)pthread_self());
  
    print_ids("main thread");
    pthread_join(tid, NULL); 
 
    Static();

    PRINT_INFO("end");
    return 0;
}
